package org.brisling.sysman.queryService;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.SysConfig;
import org.brisling.sysman.domain.SysLogs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/log/query")
public class QueryLogService extends AbstractBaseQueryService<SysLogs>{
	
	
	public QueryLogService(){
		this.moduleName = ConstSysParam.MODULE_LOG;
		this.subSystem = ConstSysParam.SUBSYSTEM_SYSMAN;
		this.tableName = this.getTableName(SysLogs.class);
		this.clazz = SysLogs.class;
		
		typeMap = this.getTypeMap(clazz);
		
		
		orderMap.put("sortedid",null);			
		
	}	
	
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
	
	
	
	@RequestMapping("/getListDomain.action")
	public ListDomain<SysLogs> getListDomain(
			@RequestBody(required=false) String body){
		orderMap = new LinkedHashMap<String,String>();
		orderMap.put("createTime", "desc");
		return super.getListDomainByConditionAndOrder(body, typeMap, orderMap,true);
	}
	
	@RequestMapping("/getList.action")
	public List<SysLogs> getList(){		
		
		
		String sql = String.format(this.T_SQL, this.tableName);
		
		return super.getAllList(sql);	
		
	}
	
	/**
	 * 根据用户id查找用户信息
	 * @param id	用户id
	 * @return 用户信息记录 
	 */
	@RequestMapping("/getOne.action")
	public SysLogs getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public SysLogs getOneByIdentify(@RequestParam(value="identify",required=false) String identify){	
		return super.getOneByIdentify(identify);
	}
	
	
	
	
	
}
